package main

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func main() {
	db, err := gorm.Open(mysql.Open("root:root@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}
	db = db.Debug()
	db.Create(&Product{Code: "D42", Price: 100})
	db.First(&Product{}, 1)
	db.Updates(&Product{Code: "F42", Price: 200})
}

type Product struct {
	gorm.Model
	Code  string `gorm:"uniqueIndex:idx_code;column:code"`
	Price uint
}
